package com.gdut.syncThread;

public class MyRunnable1 implements Runnable{
    int ticNum = 0;
    static int[] count = new int[3];
    @Override
    public void run() {
        while (true) {
            if(sell()) break;
        }
    }

    private synchronized boolean sell(){
        if(ticNum == 10000){
            return true;
        }else {
            ticNum++;
            System.out.println(Thread.currentThread().getName() + "卖" + ticNum);
            Thread.yield();
            if(Thread.currentThread().getName().equals("1num")){
                count[0]++;
            }else if(Thread.currentThread().getName().equals("2num")){
                count[1]++;
            }else {
                count[2]++;
            }
        }
        return false;
    }
}

